package org.jeecg.talentCooperation.talent.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.talentCooperation.common.vo.Result;
import org.jeecg.talentCooperation.talent.entity.TalentBasic;
import org.jeecg.talentCooperation.talent.entity.TalentFieldRel;
import org.jeecg.talentCooperation.talent.model.TalentFruitResultModel;
import org.jeecg.talentCooperation.talent.service.ITalentBasicService;
import org.jeecg.talentCooperation.talent.service.ITalentFieldRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 人才协作
 * @Author: jeecg-boot
 * @Date:   2023-8-17
 * @Version: V1.0
 */
@RestController
@RequestMapping("/ndTalent/talents/manage")
@Slf4j
public class TalentManageController {

	@Autowired
	private ITalentBasicService basicService;

	@Autowired
	private ITalentFieldRelService talentFieldRelService;

	@PostMapping(value = "/search")
	public Result<?> search(@RequestBody TalentBasic talentBasic) {

		List<TalentBasic> basicList = basicService.getTalentBasicInfoData(talentBasic);

		return Result.OK(basicList);
	}

	@PostMapping(value = "/list")
	public Result<?> list(@RequestBody TalentBasic talentBasic) {


		Integer pageNo = talentBasic.getPageNo();
		Integer pageSize = talentBasic.getPageSize();

		talentBasic.setPageNo((pageNo - 1) * pageSize);
		talentBasic.setPageSize(pageSize);

		Page<TalentBasic> talentFruitPageList = new Page<TalentBasic>(pageNo, pageSize);
		talentFruitPageList = basicService.getTalentInfoList(talentFruitPageList, talentBasic);

		return Result.OK(talentFruitPageList);
	}


	@PostMapping(value = "/saveOrUpdate")
	public Result<?> saveOrUpdate(@RequestBody TalentBasic talentBasic) {

		basicService.saveOrUpdate(talentBasic);

		QueryWrapper<TalentFieldRel> wrapper = new QueryWrapper<>();
		wrapper.eq("talent_id", talentBasic.getId());
		TalentFieldRel talentFieldRel = talentFieldRelService.getOne(wrapper);

		talentFieldRel.setTalentRealName(talentBasic.getRealName());
		talentFieldRel.setTalentAllPhoneNumber(talentBasic.getAllPhoneNumber());
		talentFieldRel.setTalentPartPhoneNumber(talentBasic.getPartPhoneNumber());
		talentFieldRel.setTalentCooperationNum(talentBasic.getCooperationNum());
		talentFieldRel.setTalentCompany(talentBasic.getCompany());
		talentFieldRel.setTalentType(talentBasic.getType());
		talentFieldRel.setTalentPhoto(talentBasic.getProfilePhoto());
		talentFieldRelService.saveOrUpdate(talentFieldRel);

		return Result.OK();
	}


	@PostMapping(value = "/delete")
	public Result<?> delete(@RequestBody TalentBasic talentBasic) {

		basicService.removeById(talentBasic);
		return Result.OK();
	}


	@PostMapping(value = "/getTalentFullInfo")
	public Result<?> getTalentFullInfo(@RequestBody TalentBasic talentBasic) {

		List<TalentBasic> basicList = basicService.getTalentBasicInfoData(talentBasic);

		return Result.OK(basicList);
	}


}
